package com.c.service.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.pool.DruidDataSource;
import com.c.model.User;
import com.c.result.SingleResult;
import com.c.service.admin.in.IAdmin;

import cn.hutool.db.Entity;
import cn.hutool.db.SqlRunner;

@Service
public class AdminService implements IAdmin{
	@Autowired
	private DruidDataSource ds;

	public SingleResult<Entity> islogin(User user) {
		SingleResult<Entity> result = new SingleResult<Entity>();
		SqlRunner runner = SqlRunner.create(ds);
		try {
			List<Entity> list = runner.query("select * from user where 1=1 and username = ? and password = ?",
					user.getUsername(), user.getPassword());
			if (list.size() > 0) {
				// Entity log = Entity.create("log").set("create_time", new DateTime(new
				// Date()).toString())
				// .set("operation", "用户登陆").set("operator", user.getUsername());
				// runner.insert(log);
				result.setData(list.get(0));
				return result;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		result.setSuccess(false);
		return result;
	}
}
